package pe.gob.sedapal.scmultimedia.rcp.view;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.eclipse.e4.ui.di.Focus;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import pe.gob.sedapal.scmultimedia.config.ApplicationContext;
import pe.gob.sedapal.scmultimedia.domain.Usuario;
import pe.gob.sedapal.scmultimedia.service.UsuarioService;

public class PruebaView {
	
	private UsuarioService usuarioService;
	private Label lblTexto;
	
	public PruebaView() {
	}

	/**
	 * Create contents of the view part.
	 */
	@PostConstruct
	public void createControls(Composite parent) {
		parent.setLayout(null);
		
		lblTexto = new Label(parent, SWT.NONE);
		lblTexto.setBounds(90, 62, 119, 24);
		lblTexto.setText("Texto");
		
		Button btnPrueba = new Button(parent, SWT.NONE);
		btnPrueba.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				usuarioService= (UsuarioService)ApplicationContext.getBean(UsuarioService.class);								
				Usuario user= usuarioService.listarUsuariosActivos().get(0);
				System.out.println(user);
				lblTexto.setText(user.getDni()+"-"+user.getNombre());
			}
		});
		btnPrueba.setBounds(276, 121, 93, 72);
		btnPrueba.setText("Prueba");
	}

	@PreDestroy
	public void dispose() {
	}

	@Focus
	public void setFocus() {
		// TODO	Set the focus to control
	}

	public Label getLblTexto() {
		return lblTexto;
	}
}
